<!DOCTYPE html>
<html lang="zh">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>注册</title>

    <!-- Custom fonts for this template-->
    <link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
    <link
            href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i"
            rel="stylesheet">

    <!-- Custom styles for this template-->
    <link href="css/sb-admin-2.min.css" rel="stylesheet">
    <!--    <link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">-->
    <link href="css/font-awesome.min.css" rel="stylesheet">

</head>

<body class="bg-gradient-primary" onkeydown="if(event.keyCode==13){login_btn.click()}">

<div class="container">

    <div style="width: 900px; display: block; margin: 0 auto" class="card o-hidden border-0 shadow-lg my-5">
        <div class="card-body p-0">
            <!-- Nested Row within Card Body -->
            <div class="row">
                <div class="col-lg-5 d-none d-lg-block ">
                    <img src="photo/house2.jpeg" width="105%" height="100%">
                </div>
                <div class="col-lg-7">
                    <div class="p-5">
                        <div class="text-center">
                            <h1 class="h4 text-gray-900 mb-4">创建一个用户！</h1>
                        </div>
                        <form class="user" id="form1" onsubmit="return false" action="##" >
                            <div class="form-group">
                                <!--                                    <div class="col-sm-6 mb-3 mb-sm-0">-->
                                <input type="text" style="font-size: 18px" class="form-control form-control-user"
                                       name="name" id="name" placeholder="用户名"/>
                                <!--                                    </div>-->
                                <!--                                    <div class="col-sm-6">-->
                                <!--                                        <input type="text" class="form-control form-control-user" id="exampleLastName"-->
                                <!--                                            placeholder="Last Name">-->
                                <!--                                    </div>-->
                            </div>
                            <!--                                <div class="form-group">-->
                            <!--                                    <input type="email" class="form-control form-control-user" id="exampleInputEmail"-->
                            <!--                                        placeholder="Email Address">-->
                            <!--                                </div>-->
                            <div class="form-group">
                                <!--                                    <div class="col-sm-6 mb-3 mb-sm-0">-->
                                <input type="password" style="font-size: 18px" class="form-control form-control-user"
                                       name="password" id="password" placeholder="密码"/>
                                <!--                                    </div>-->
                                <!--                                    <div class="col-sm-6">-->
                                <!--                                        <input type="password" class="form-control form-control-user"-->
                                <!--                                            id="exampleRepeatPassword" placeholder="Repeat Password">-->
                                <!--                                    </div>-->
                            </div>
                            <div style="font-size: 18px">
                                你想:
                                <div style="text-align: center">
                                    租房&ensp;<input type="radio" name="type" id="type1" value="1"/>
                                    &ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;
                                    将房租出&ensp;<input type="radio" name="type" id="type2" value="2"/>
                                </div>
                            </div>
                            <br>
                            <input type="button" value="注册" onclick="register()" style="font-size: 18px;" class="btn btn-primary btn-user btn-block" id="login_btn">
                            <hr>
                            <!--                                <a href="index.html" class="btn btn-google btn-user btn-block">-->
                            <!--                                    <i class="fab fa-google fa-fw"></i> Register with Google-->
                            <!--                                </a>-->
                            <!--                                <a href="index.html" class="btn btn-facebook btn-user btn-block">-->
                            <!--                                    <i class="fab fa-facebook-f fa-fw"></i> Register with Facebook-->
                            <!--                                </a>-->
                        </form>
                        <br>
                        <div class="text-center">
                            <a style="font-size: 15px" class="small" href="login.html">已经有一个用户了？点此登录！</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>

<!-- Bootstrap core JavaScript-->
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

<!-- Core plugin JavaScript-->
<script src="vendor/jquery-easing/jquery.easing.min.js"></script>

<!-- Custom scripts for all pages-->
<script src="js/sb-admin-2.min.js"></script>

</body>

<script>
    function register() {
        $.ajax({
            url: 'user/register',
            method: 'POST',
            dataType: 'json',
            data: $('#form1').serialize(),
            success: function (result) {
                console.log(result);//打印服务端返回的数据(调试用)
                if (result.status == 200) {
                    alert(result.msg);
                    if(result.msg=="注册成功"){
                        sessionStorage.removeItem("userInfo");
                        sessionStorage.setItem("userInfo", JSON.stringify(result.data));
                        window.location.href = 'main.html';
                    }
                }
            },
            error: function () {
                alert("注册失败，请重新尝试！！");
            }
        })
    }
</script>

</html>